package cn.mengfly.fxtest.app;

import javafx.application.Application;
import javafx.geometry.Rectangle2D;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.TilePane;
import javafx.stage.Stage;

/**
 * @author Mengfly
 * @date 2021/5/27 23:44
 */
public class ImageApp extends Application {

    private static final String IMAGE_LOC = "file:///D:/mydata/bizhi/ChMkJ1bKyNOIPz10AApS9wY1PSoAALIHQDUFxMAClMP637.jpg";


    @Override
    public void start(Stage primaryStage) throws Exception {
        Image image2 = new Image(IMAGE_LOC, 360, 360, true, true);
        Image image3 = new Image(IMAGE_LOC, 360, 360, false, true);
        Image image4 = new Image(IMAGE_LOC);

        ImageView iv1 = new ImageView(IMAGE_LOC);
        ImageView iv2 = new ImageView(image2);
        ImageView iv3 = new ImageView(image3);
        ImageView iv4 = new ImageView(image4);
        Rectangle2D viewPortRect = new Rectangle2D(20, 20, 100, 100);

        iv1.setViewport(viewPortRect);
        iv4.setPreserveRatio(true);
        iv4.setFitWidth(360);
        iv4.setFitHeight(360);

        iv4.setViewport(viewPortRect);

        TilePane tilePane = new TilePane(iv1, iv2, iv3, iv4);
        tilePane.setPrefColumns(2);

        Scene scene = new Scene(tilePane);

        primaryStage.setTitle("ImageApp");
        primaryStage.setScene(scene);
        primaryStage.show();
    }


}
